package com.dcy.seataorder.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dcy.common.annotation.Log;
import com.dcy.common.model.R;
import com.dcy.db.base.model.PageResult;
import com.dcy.seataorder.biz.dto.input.OrderTblCreateInputDTO;
import com.dcy.seataorder.biz.dto.input.OrderTblSearchInputDTO;
import com.dcy.seataorder.biz.dto.input.OrderTblUpdateInputDTO;
import com.dcy.seataorder.biz.dto.output.OrderTblListOutputDTO;
import com.dcy.seataorder.biz.dtomapper.MOrderTblMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import com.dcy.seataorder.api.model.OrderTbl;
import com.dcy.seataorder.biz.service.OrderTblService;
import org.springframework.web.bind.annotation.*;
import com.dcy.db.base.controller.BaseController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dcy
 * @since 2021-04-23
 */
@RestController
@RequestMapping("/order-tbl")
@Api(value = "OrderTblController", tags = {"操作接口"})
public class OrderTblController extends BaseController<OrderTblService,OrderTbl> {

    @Autowired
    private MOrderTblMapper mOrderTblMapper;

    @Log
    @ApiOperation(value = "字典类型分页查询", notes = "字典类型分页查询")
    @GetMapping("/page")
    public R<PageResult<OrderTblListOutputDTO>> pageList(OrderTblSearchInputDTO orderTblSearchInputDTO) {
        // 转换model
        OrderTbl orderTbl = mOrderTblMapper.toOrderTbl(orderTblSearchInputDTO);
        // 获取源对象
        IPage<OrderTbl> pageListByListInputDTO = baseService.getPageListByEntity(orderTbl);
        // 转换新对象
        List<OrderTblListOutputDTO> orderTblListOutputDTOS = mOrderTblMapper.toList(pageListByListInputDTO.getRecords());
        // 返回业务分页数据
        return success(toPageDTO(pageListByListInputDTO, orderTblListOutputDTOS));
    }

    @Log
    @ApiOperation(value = "添加", notes = "添加")
    @PostMapping("/save")
    public R<Boolean> save(@ApiParam @RequestBody OrderTblCreateInputDTO orderTblCreateInputDTO) {
        OrderTbl orderTbl = mOrderTblMapper.toOrderTbl(orderTblCreateInputDTO);
        return super.save(orderTbl);
    }

    @Log
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping(value = "/update")
    public R<Boolean> update(@ApiParam @RequestBody OrderTblUpdateInputDTO orderTblUpdateInputDTO) {
        OrderTbl orderTbl = mOrderTblMapper.toOrderTbl(orderTblUpdateInputDTO);
        return super.update(orderTbl);
    }

    @Log
    @ApiOperation(value = "删除", notes = "删除")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true)
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@RequestParam String id) {
        return super.delete(id);
    }

    @Log
    @ApiOperation(value = "根据list删除", notes = "根据list删除")
    @PostMapping(value = "/deleteBatch")
    public R<Boolean> deleteBatch(@ApiParam @RequestBody List<String> idList) {
        return super.deleteBatch(idList);
    }

}
